/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.timesoft.setting.app.webservice;

import com.timesoft.common.bean.ResponseCommon;
import com.timesoft.common.convertor.Base64ConvertorUtils;
import com.timesoft.hibernate.bean.SettingFormatDate;
import com.timesoft.hibernate.bean.SettingFormatNumber;
import com.timesoft.hibernate.core.SettingFormatDateCore;
import com.timesoft.hibernate.core.SettingFormatNumberCore;
import com.timesoft.webservice.client.setting.SettingWebService;
import javax.jws.WebService;
import org.apache.log4j.Logger;

/**
 *
 * @author sorasaks
 */
@WebService(targetNamespace = "http://setting.timesoft.com/",
        endpointInterface = "com.timesoft.webservice.client.setting.SettingWebService",
        serviceName = "SettingWs")
public class SettingWs implements SettingWebService {

    private static final Logger LOG = Logger.getLogger(SettingWs.class);
    private static final Base64ConvertorUtils base64 = new Base64ConvertorUtils();

    @Override
    public String getSettingFormatNumber() throws Exception {
        ResponseCommon common = new ResponseCommon();
        try {
            SettingFormatNumber setting = SettingFormatNumberCore.getSettingFormatNumber();
            common.setValue(base64.genericObjToString(setting));
            common.setFlag(Boolean.TRUE);
        } catch (Exception ex) {
            LOG.error(ex.getMessage(), ex);
            common.setValue(null);
            common.setFlag(Boolean.FALSE);
            common.setMessage(ex.getMessage());
        }

        return base64.genericObjToString(common);
    }

    @Override
    public String getSettingFormatDate() throws Exception {
        ResponseCommon common = new ResponseCommon();
        try {
            SettingFormatDate setting = SettingFormatDateCore.getSettingFormatDate();
            common.setValue(base64.genericObjToString(setting));
            common.setFlag(Boolean.TRUE);
        } catch (Exception ex) {
            LOG.error(ex.getMessage(), ex);
            common.setValue(null);
            common.setFlag(Boolean.FALSE);
            common.setMessage(ex.getMessage());
        }

        return base64.genericObjToString(common);
    }

}
